package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.member.BindThirdModel
import com.asia5b.a5mall.middleware.utils.showMessage
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   会员安全逻辑控制器
 */
class MemberSecurityActivityVM:SimpleViewModel() {

    /*
    http://47.88.223.5:4001/account-binder/list
    获取绑定列表
     */
    fun getBinderList() {
        val observable = memberApi.getBinderList()
        baseSubscribe(observable, Consumer {
//            providerView().getBinderListResult(it)
            getBinderListResultLiveData.value=it
        })
    }
    val getBinderListResultLiveData=MutableLiveData<ArrayList<BindThirdModel>>()

    /*
    http://47.88.223.5:4001/account-binder/list
     qq
    weixin
    weibo
    alipay
    todo 支付宝绑定
     */
    fun openidBind(bindThirdModel: BindThirdModel, type: String, uuid: String) {
        val observable = memberApi.connectWechat()
                .flatMap {
                    memberApi.openidBind()
                }
        baseSubscribe(observable, Consumer {
            showMessage(R.string.绑定成功)
//            providerView().openidBindResult(it, bindThirdModel)
            openidBindResultLiveData.value=bindThirdModel
        })
    }

    val openidBindResultLiveData=MutableLiveData<BindThirdModel>()

    /**
     * 绑定
     */
    fun openidBind2(bindThirdModel: BindThirdModel, type: String, uuid: String) {
        val observable = memberApi.openidBind2(uuid, bindThirdModel.union_type)
        baseSubscribe(observable, Consumer {
            showMessage(R.string.绑定成功)
//            providerView().openidBindResult(it, bindThirdModel)
            openidBindResultLiveData.value=bindThirdModel
        })
    }

    /**
     * 解绑
     */
    fun unBind(type: String) {
        val observable = memberApi.unbind2(type)
        baseSubscribe(observable, Consumer {
            showMessage(R.string.解绑成功)
//            providerView().unBindResult(type)
            unBindResultLiveData.value=type
        })
    }

    val unBindResultLiveData=MutableLiveData<String>()

}